package com.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.model.auto.Achievement;
import com.service.IAchievementService;
import com.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/achievement")
public class AchievementController{
    @Autowired
    private IAchievementService achievementService;

    @GetMapping("/getAchievement")
    public R getAchievement(String stuId) {
        List<Achievement> list = achievementService.list(new LambdaQueryWrapper<Achievement>()
                .eq(Achievement::getStuId, stuId));
        return R.ok(list);
    }

    @PostMapping("SaveOrUpdateAchievement")
    public R SaveOrUpdateAchievement(@RequestBody List<Achievement> achievement) {
        boolean result = achievementService.saveOrUpdateBatch(achievement);
        if (!result) {
            return R.error();
        }
        return R.ok();
    }
    //删除平时成绩
    @DeleteMapping("deleteAchievement")
    public R deleteAchievement(Integer id){
        boolean result =achievementService.removeById(id);
        if (!result) {
            return R.error();
        }
        return R.ok();
    }
}
